package com.woniuxy.rms.util;

import lombok.Data;
/**
 * Auther: ChenGang  <br/>
 * Date: 2020/3/23 0023:下午 8:48  <br/>
 * Description:封装返回结果
 */
@Data
public class DataResult <T>{
    private Integer code;//状态码
    private String message;//返回信息
    private T data;//返回数据

    public DataResult() {
    }

    public DataResult(String message) {
        this.message = message;
    }
    public DataResult(Integer code , String message) {
        this.message = message;
        this.code = code;
    }
    public DataResult(Integer code , String message, T data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }
    //成功并返回数据
    public static <T> DataResult success(T data){
        return new DataResult(ResultUtil.SUCCESS.getCode(),ResultUtil.SUCCESS.getMessage(),data);
    }
    //成功不返回数据
    public static DataResult success(String message){
        return new DataResult(ResultUtil.SUCCESS.getCode(),message);
    }
    //成功不返回数据
    public static DataResult success(){
        return new DataResult(ResultUtil.SUCCESS.getCode(),ResultUtil.SUCCESS.getMessage());
    }
    //失败
    public static DataResult failed(){
        return new DataResult(ResultUtil.FAILED.getCode(),ResultUtil.FAILED.getMessage());
    }

    public static DataResult failed(String message) {
        return new DataResult(ResultUtil.FAILED.getCode(),message);
    }
}